﻿using System;
using SuppKids.Core;
using SuppKids.Core.Domain;

namespace SuppKids.ViewModels
{
	public class ProductAtStorageViewModel : ViewModelBase
	{
		private readonly ProductAtStorage productAtStorage;
		private double balance;

		public ProductAtStorageViewModel()
			: this(new ProductAtStorage(), 0)
		{
			this.DeliveryDate = DateTime.Now.Date;
		}

		public ProductAtStorageViewModel(ProductAtStorage productAtStorage, double balance)
		{
			this.productAtStorage = productAtStorage;
			this.balance = balance;
		}

		public ProductAtStorage ProductAtStorage
		{
			get
			{
				return this.productAtStorage;
			}
		}

		public string Bill
		{
			get
			{
				return this.productAtStorage.Bill;
			}

			set
			{
				this.productAtStorage.Bill = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Bill));
			}
		}

		public string Recipient
		{
			get
			{
				return this.productAtStorage.Recipient;
			}

			set
			{
				this.productAtStorage.Recipient = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Recipient));
			}
		}

		public double Price
		{
			get
			{
				return this.productAtStorage.Price;
			}

			set
			{
				this.productAtStorage.Price = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Price));
			}
		}

		public string Supplier
		{
			get
			{
				return this.productAtStorage.Supplier;
			}

			set
			{
				this.productAtStorage.Supplier = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Supplier));
			}
		}

		public double ConsumptAmount
		{
			get
			{
				return this.productAtStorage.ConsumptAmount;
			}

			set
			{
				this.productAtStorage.ConsumptAmount = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.ConsumptAmount));
			}
		}

		public double DeliveryAmount
		{
			get
			{
				return this.productAtStorage.DeliveryAmount;
			}

			set
			{
				this.productAtStorage.DeliveryAmount = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.DeliveryAmount));
			}
		}

		public string QualityCertificateNumber
		{
			get
			{
				return this.productAtStorage.QualityCertificateNumber;
			}

			set
			{
				this.productAtStorage.QualityCertificateNumber = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.QualityCertificateNumber));
			}
		}

		public bool IsTransient
		{
			get
			{
				return this.productAtStorage.IsTransient;
			}
		}

		public DateTime DeliveryDate
		{
			get
			{
				return this.productAtStorage.DeliveryDate;
			}

			set
			{
				this.productAtStorage.DeliveryDate = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.DeliveryDate));
			}
		}

		public virtual double Balance
		{
			get
			{
				return balance;
			}
			set
			{
				this.balance = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Balance));
			}
		}

		public Product Product
		{
			get
			{
				return this.productAtStorage.Product;
			}

			set
			{
				this.productAtStorage.Product = value;
				this.OnPropertyChanged(Lambda.Property<ProductAtStorageViewModel>(x => x.Product));
			}
		}
        public string Name
        {
            get
            {
                if (this.productAtStorage.Product != null)
                    return this.productAtStorage.Product.Name;
                return "";
            }
        }
        public int Id
        {
            get
            {
                if (this.productAtStorage.Product != null)
                    return this.productAtStorage.Product.Id;
                return 0;
            }
        }
		public override bool AllFieldsIsNotEmpty
		{
			get
			{
				return
					!string.IsNullOrWhiteSpace(this.Bill) &&
					!string.IsNullOrWhiteSpace(this.Recipient) &&
					!string.IsNullOrWhiteSpace(this.Supplier) &&
					//this.DeliveryAmount != default(double) &&
					this.Price != default(double) &&
					this.DeliveryDate != default(DateTime) &&
					this.Product != null;
			}
		}
	}
}